# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Médéric Boquien <mboquien@free.fr>

_pkg=pyerfa
pkgname=python-${_pkg}
pkgver=2.0.0.3
pkgrel=1
pkgdesc="Bindings for ERFA routines"
arch=(loong64 x86_64)
url="https://pyerfa.readthedocs.io/"
license=(BSD)
depends=(erfa glibc python python-numpy)
makedepends=(python-build python-installer python-jinja python-packaging python-setuptools-scm python-wheel)
checkdepends=(python-pytest)
source=(https://files.pythonhosted.org/packages/source/p/${_pkg}/${_pkg}-${pkgver}.tar.gz)
sha256sums=('d77fbbfa58350c194ccb99e5d93aa05d3c2b14d5aad8b662d93c6ad9fff41f39')

prepare() {
  # we don't care about oldest-supported-numpy because we provide numpy
  sed 's/oldest-supported-//' -i $_pkg-$pkgver/pyproject.toml
}

build() {
  cd ${_pkg}-${pkgver}
  export PYERFA_USE_SYSTEM_LIBERFA=1
  python -m build --wheel --no-isolation
}

check() {
  sed -e '/addopts/d' -i ${_pkg}-${pkgver}/setup.cfg
  local python_version=$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')
  cd ${_pkg}-${pkgver}/build/lib.linux-${CARCH}-cpython-${python_version}/erfa
  pytest -vv --color=yes
}

package() {
  cd ${_pkg}-${pkgver}
  python -m installer --destdir="$pkgdir" dist/*.whl
  rm -r "${pkgdir}"$(python -c "import site; print(site.getsitepackages()[0])")/erfa/tests
  install -Dm644 LICENSE.rst -t "${pkgdir}"/usr/share/licenses/$pkgname/
}
